<{include file="header.tpl"}>
<body leftmargin="4" topmargin="4" marginwidth="4" marginheight="4" onLoad="loadContents()">
<script language="Javascript">
var staffname = "<{$staffname}>";
var chatstatus = 0;

function updateChatStatus(newchatstatus)
{
	chatstatus = newchatstatus;
}

function writeToDoc(data) {
	document.open();
	document.write(data);
	document.close();
}

function writeToDiv(data) {
	var divobj = browserObject("buffer");
	divobj.innerHTML = divobj.innerHTML+data;

	if (typeof(scrollBy) != "undefined")
	{
		window.scrollBy(0, 6000);
	} else if (typeof(scroll) != "undefined") {
		window.scrollBy(0, 6000);
	}
}

function displaySelfMessage(staffmsg) {
	if (chatstatus == 2)
	{
		var towrite = "<span class='staffname'>"+htmlize(staffname)+":</span><span class='staffmessage'>&nbsp;"+htmlize(staffmsg)+"</span><BR />";

		writeToDiv(towrite);	
	} else if (chatstatus == 1) {
		displayMessage("<{$language[errorchatnotstarted]}>");
	} else {
		displayMessage("<{$language[errorchatended]}>");
	}
}

function clearText()
{
	var divobj = browserObject("buffer");
	divobj.innerHTML = "";

	displayMessage("<b><{$language[fullname]}>: </b><{$fullname}><br/><b><{$language[email]}>: </b><{$email}><br/><b><{$language[department]}>: </b><{$department}>");
}

function startViewShare(url)
{
	window.external.JSOpenURL('<{$chatsessionid}>', url);
}

function displayStatusMessage(dispmsg) {
	writeToDiv("<span class='chatstatusmsg'>"+dispmsg+"</span><br />");
}

function displayMessage(dispmsg) {
	writeToDiv("<table width='100%'  border='0' cellspacing='0' cellpadding='1'><tr><td bgcolor='#CCCCCC'><table width='100%'  border='0' cellspacing='0' cellpadding='3'><tr><td bgcolor='#F7F7EF'><font face='Verdana, Arial, Helvetica' size='2'><div style='FONT-SIZE: 11px; COLOR: #333333; FONT-FAMILY: Verdana, Arial;'>"+ dispmsg +"</span></font></td></tr></table></td></tr></table><br />");
}

// =========== XML HTTP REQUEST STUFF ==============
var xmlhttp;
var xmlaction = "";
var xmlsubset = "";

function loadXMLHTTPRequest(url) {
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = processStatusChange;
		try {
			xmlhttp.open("GET", url, true);
			xmlhttp.send(null);
		} catch (e) {
			alert("XMLHttpRequest Open Failed!\nThis can happen if the URL you are accessing the product from (http://www.domain.com/support) is different than the one specified under Admin CP > Settings > General (Ex: http://support.domain.com/). Due to limitations of AJAX, The URL should be *exactly* the same as specified under Product URL setting.");
		}
	} else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp) {
			xmlhttp.onreadystatechange = processStatusChange;
			try {
				xmlhttp.open("GET", url, true);
				xmlhttp.send();
			} catch (e) {
				alert("XMLHttpRequest Open Failed!\nThis can happen if the URL you are accessing the product from (http://www.domain.com/support) is different than the one specified under Admin CP > Settings > General (Ex: http://support.domain.com/). Due to limitations of AJAX, The URL should be *exactly* the same as specified under Product URL setting.");
			}
		}
	}
}

var doWinappLoop = true;
function processStatusChange() {
	if (xmlhttp.readyState == 4) {
		if (xmlhttp.status == 200) {
			eval(xmlhttp.responseText);
			if (window.parent.doWinappLoop)
			{
				setTimeout("loadContents();", <{$refreshinterval}>);
			}
		}
	}
}


function loadContents() {
	//writeToDiv("<{$swiftpath}>winapp/index.php?_m=livesupport&_a=chatloopframe&sessionid=<{$sessionid}>&chatsessionid=<{$chatsessionid}>&visitorsessionid=<{$visitorsessionid}>&chatchildid=<{$chatchildid}>");
	loadXMLHTTPRequest("index.php?_m=livesupport&_a=chatloopframe&sessionid=<{$sessionid}>&chatsessionid=<{$chatsessionid}>&visitorsessionid=<{$visitorsessionid}>&chatchildid=<{$chatchildid}>");
}

function pushImage(url) {
	writeToDiv("<br /><hr size='1'><img src='"+url+"' border='0'><hr size='1'><br />");
}

function getDivHTML()
{
	var divobj = browserObject("buffer");
	return divobj.innerHTML;
}

function printConvo()
{
	window.print();
}

function pushStart() {
	writeToDiv("<br /><hr size='1'>");
}

function pushEnd() {
	writeToDiv("<hr size='1'><br />");
}

function pushCode(htmldata) {
	writeToDiv(htmldata);
}

function displayNewLine() {
	writeToDiv("<br />");
}

function doMessageAlert()
{
	window.external.JSMessageAlert('<{$chatsessionid}>');
}

function doUserTyping(staffname) {
	typingmsg = "<{$language[typingmsg]}>";
	typingmsgfinal = typingmsg.replace("%s", staffname);

	window.external.JSUpdateStatusBar('<{$chatsessionid}>', typingmsg);
}

function resetUserTyping() {
	window.external.JSUpdateStatusBar('<{$chatsessionid}>', '');
}

function startVoiceChat(ipaddress, port) {
	window.external.JSStartVoiceChat('<{$chatsessionid}>', ipaddress, port, "30");
}


function isLiveResponse()
{
	if (window.external.JSIsLiveResponse() == true)
	{
		return true;
	} else {
		return false;
	}
}

bIsLiveResponse = isLiveResponse();

if (!bIsLiveResponse)
{
	alert("<{$language[noliveresponseerror]}>");
}

</script>
<div id="buffer" style="WIDTH: 100%; HEIGHT: 100%;"><table width='100%'  border='0' cellspacing='0' cellpadding='1'><tr><td bgcolor='#CCCCCC'><table width='100%'  border='0' cellspacing='0' cellpadding='3'><tr><td bgcolor='#F7F7EF'><font face='Verdana, Arial, Helvetica' size='2'><div style='FONT-SIZE: 11px; COLOR: #333333; FONT-FAMILY: Verdana, Arial;'><b><{$language[fullname]}>: </b><{$fullname}><br/><b><{$language[email]}>: </b><{$email}><br/><b><{$language[department]}>: </b><{$department}></span></font></td></tr></table></td></tr></table><br /></div>
<!--<div style="display: block;" name="iframeblock">
<iframe src="index.php?_m=livesupport&_a=chatloopframe&sessionid=<{$sessionid}>&chatsessionid=<{$chatsessionid}>&visitorsessionid=<{$visitorsessionid}>&chatchildid=<{$chatchildid}>" name="loopframe" border="1"></iframe>-->
</div>
</body>
</html>